/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaPrincipal.java
 *
 * Created on 6/Jan/2012, 15:44:56
 */
package gardenmaker;

import java.awt.Component;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;


/**
 *
 * @author lenny
 */
public class JanelaPrincipal extends javax.swing.JFrame {
    
    Projeto projeto;

    /** Creates new form JanelaPrincipal */
    public JanelaPrincipal() {
        initComponents();
        areaDesenho.setSize(2000, 2000);
        Projeto projeto = new Projeto(null);
        this.projeto=projeto;
        areaDesenho.setProjeto(projeto);
        projeto.setAreaDesenho(areaDesenho);
        areaDesenho.setJanelaPrincipal(this);
        toolLimite.setProjeto(projeto);
        
    //tree.setVerticalTextPosition(SwingConstants.BOTTOM);
    //tree.setHorizontalTextPosition(SwingConstants.CENTER);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bGroupFlora = new javax.swing.ButtonGroup();
        bGroupLimite = new javax.swing.ButtonGroup();
        bGroupOrnamento = new javax.swing.ButtonGroup();
        bGroupVarios = new javax.swing.ButtonGroup();
        bGroupTubagem = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel4 = new javax.swing.JPanel();
        jToggleButton3 = new javax.swing.JToggleButton();
        jToggleButton4 = new javax.swing.JToggleButton();
        jToggleButton5 = new javax.swing.JToggleButton();
        jToggleButton6 = new javax.swing.JToggleButton();
        jPanel2 = new javax.swing.JPanel();
        tree = new javax.swing.JToggleButton();
        bush = new javax.swing.JToggleButton();
        jToggleButton1 = new javax.swing.JToggleButton();
        jToggleButton2 = new javax.swing.JToggleButton();
        jPanel5 = new javax.swing.JPanel();
        jToggleButton7 = new javax.swing.JToggleButton();
        jToggleButton8 = new javax.swing.JToggleButton();
        jToggleButton9 = new javax.swing.JToggleButton();
        jToggleButton10 = new javax.swing.JToggleButton();
        jPanel1 = new javax.swing.JPanel();
        bRectangle = new javax.swing.JToggleButton();
        bCircle = new javax.swing.JToggleButton();
        jPanel3 = new javax.swing.JPanel();
        bTubo = new javax.swing.JToggleButton();
        jToggleButton12 = new javax.swing.JToggleButton();
        jToggleButton13 = new javax.swing.JToggleButton();
        jToggleButton11 = new javax.swing.JToggleButton();
        jToggleButton14 = new javax.swing.JToggleButton();
        jToggleButton15 = new javax.swing.JToggleButton();
        jToggleButton16 = new javax.swing.JToggleButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        areaDesenho = new gardenmaker.AreaDesenho();
        cardHolder = new javax.swing.JPanel();
        toolLimite = new gardenmaker.ToolLimite();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        bListaMateriais = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTabbedPane1.setTabPlacement(javax.swing.JTabbedPane.LEFT);
        jTabbedPane1.setFont(new java.awt.Font("Tahoma", 0, 14));

        bGroupOrnamento.add(jToggleButton3);
        jToggleButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rockicon.png"))); // NOI18N
        jToggleButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rockClicked(evt);
            }
        });

        bGroupOrnamento.add(jToggleButton4);
        jToggleButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Fountain-icon.png"))); // NOI18N
        jToggleButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                fountaneClicked(evt);
            }
        });

        bGroupOrnamento.add(jToggleButton5);
        jToggleButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/poolicon.png"))); // NOI18N
        jToggleButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                poolClicked(evt);
            }
        });

        bGroupOrnamento.add(jToggleButton6);
        jToggleButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/lakeicon.png"))); // NOI18N
        jToggleButton6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lakeClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToggleButton3)
                    .addComponent(jToggleButton4)
                    .addComponent(jToggleButton5)
                    .addComponent(jToggleButton6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToggleButton3)
                .addGap(18, 18, 18)
                .addComponent(jToggleButton4)
                .addGap(18, 18, 18)
                .addComponent(jToggleButton5)
                .addGap(18, 18, 18)
                .addComponent(jToggleButton6)
                .addContainerGap(230, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Ornaments", jPanel4);

        bGroupFlora.add(tree);
        tree.setIcon(new javax.swing.ImageIcon(getClass().getResource("/treeIcon.png"))); // NOI18N
        tree.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        tree.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        tree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                treeClicked(evt);
            }
        });

        bGroupFlora.add(bush);
        bush.setIcon(new javax.swing.ImageIcon(getClass().getResource("/bushIcon.png"))); // NOI18N
        bush.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bush.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bush.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bushClicked(evt);
            }
        });

        bGroupFlora.add(jToggleButton1);
        jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/palmicon.png"))); // NOI18N
        jToggleButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                palmClicked(evt);
            }
        });

        bGroupFlora.add(jToggleButton2);
        jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/flowericon.png"))); // NOI18N
        jToggleButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                flowerClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToggleButton2)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(tree, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(bush, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jToggleButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tree)
                .addGap(18, 18, 18)
                .addComponent(bush)
                .addGap(18, 18, 18)
                .addComponent(jToggleButton1)
                .addGap(18, 18, 18)
                .addComponent(jToggleButton2)
                .addContainerGap(230, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Flora", jPanel2);

        bGroupVarios.add(jToggleButton7);
        jToggleButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/houseicon.png"))); // NOI18N
        jToggleButton7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                houseClicked(evt);
            }
        });

        bGroupVarios.add(jToggleButton8);
        jToggleButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/bridgeicon.png"))); // NOI18N
        jToggleButton8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bridgeClicked(evt);
            }
        });

        bGroupVarios.add(jToggleButton9);
        jToggleButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/wallicon.png"))); // NOI18N
        jToggleButton9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                wallClicked(evt);
            }
        });

        bGroupVarios.add(jToggleButton10);
        jToggleButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fenceicon.png"))); // NOI18N
        jToggleButton10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                fenceClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jToggleButton8, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 55, Short.MAX_VALUE)
                            .addComponent(jToggleButton9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 55, Short.MAX_VALUE)
                            .addComponent(jToggleButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 55, Short.MAX_VALUE))
                        .addGap(157, 157, 157))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jToggleButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jToggleButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jToggleButton8)
                .addGap(4, 4, 4)
                .addComponent(jToggleButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jToggleButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(216, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Various Objects", jPanel5);

        jPanel1.setFont(new java.awt.Font("Tahoma", 0, 18));

        bGroupLimite.add(bRectangle);
        bRectangle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rectangle.png"))); // NOI18N
        bRectangle.setText("Square");
        bRectangle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bRectangle.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bRectangle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                squareClicked(evt);
            }
        });

        bGroupLimite.add(bCircle);
        bCircle.setIcon(new javax.swing.ImageIcon(getClass().getResource("/circle.png"))); // NOI18N
        bCircle.setText("Circle");
        bCircle.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bCircle.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bCircle.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                circleClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(bRectangle, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bCircle, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE))
                .addGap(218, 218, 218))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bRectangle)
                .addGap(18, 18, 18)
                .addComponent(bCircle)
                .addContainerGap(308, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Limites", jPanel1);

        bGroupTubagem.add(bTubo);
        bTubo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pipeiconH.png"))); // NOI18N
        bTubo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tuboClicked(evt);
            }
        });

        bGroupTubagem.add(jToggleButton12);
        jToggleButton12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/fauceticon.png"))); // NOI18N
        jToggleButton12.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                faucetClicked(evt);
            }
        });

        bGroupTubagem.add(jToggleButton13);
        jToggleButton13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/elbow.png"))); // NOI18N
        jToggleButton13.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                elbowClicked(evt);
            }
        });

        bGroupTubagem.add(jToggleButton11);
        jToggleButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tunion.png"))); // NOI18N
        jToggleButton11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                uniontClicked(evt);
            }
        });

        bGroupTubagem.add(jToggleButton14);
        jToggleButton14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/end.png"))); // NOI18N
        jToggleButton14.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                endClicked(evt);
            }
        });

        bGroupTubagem.add(jToggleButton15);
        jToggleButton15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pipeiconV.png"))); // NOI18N
        jToggleButton15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tubohClicked(evt);
            }
        });

        jToggleButton16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cross.png"))); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bTubo, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToggleButton12)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jToggleButton11, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                        .addComponent(jToggleButton13, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                        .addComponent(jToggleButton15, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jToggleButton16, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                        .addComponent(jToggleButton14, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 50, Short.MAX_VALUE)))
                .addGap(79, 79, 79))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jToggleButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bTubo, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToggleButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addComponent(jToggleButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToggleButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jToggleButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToggleButton16, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Plumbing", jPanel3);

        jScrollPane1.setPreferredSize(new java.awt.Dimension(5000, 5000));

        areaDesenho.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout areaDesenhoLayout = new javax.swing.GroupLayout(areaDesenho);
        areaDesenho.setLayout(areaDesenhoLayout);
        areaDesenhoLayout.setHorizontalGroup(
            areaDesenhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 3000, Short.MAX_VALUE)
        );
        areaDesenhoLayout.setVerticalGroup(
            areaDesenhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 3000, Short.MAX_VALUE)
        );

        jScrollPane1.setViewportView(areaDesenho);

        cardHolder.setPreferredSize(new java.awt.Dimension(740, 70));
        cardHolder.setLayout(new java.awt.CardLayout());

        jMenu1.setText("File");

        jMenuItem1.setText("New");
        jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                fileNew(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Open");
        jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                fileOpen(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText("Save");
        jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                fileSave(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");
        jMenuBar1.add(jMenu2);

        bListaMateriais.setText("Material List");
        bListaMateriais.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bListaMateriaisMouseClicked(evt);
            }
        });
        jMenuBar1.add(bListaMateriais);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(toolLimite, javax.swing.GroupLayout.DEFAULT_SIZE, 944, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cardHolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1489, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cardHolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(38, 38, 38))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(toolLimite, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
                        .addGap(20, 20, 20))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fileOpen(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fileOpen
        File currentFileName;
       
        if(!projeto.getDadosAlterados()){
            currentFileName= showJFileChooser(null, 1);
            Projeto projeto = new Projeto(currentFileName);
            this.projeto=projeto;
        } else {
        showJOPane(false);
        }
            repaint();
    }//GEN-LAST:event_fileOpen

    private void fileNew(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fileNew
         File selFile;
       
        if(!projeto.getDadosAlterados()){
            showJFileChooser(null, 0);
            Projeto projeto = new Projeto(null);
            this.projeto=projeto;
            System.out.println("novo projecto sem dados alterados");
        } else {
            
        showJOPane(true);
        }
            repaint();
    }//GEN-LAST:event_fileNew

    private void fileSave(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fileSave
        checkSave();
    }//GEN-LAST:event_fileSave

    private void treeClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_treeClicked
        projeto.setEstado(projeto.ESTADO_ADD_TREE);
        
        System.out.println("estado atual:" + projeto.getEstado());
    }//GEN-LAST:event_treeClicked

    private void bushClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bushClicked
        // TODO add your handling code here:
        projeto.setEstado(projeto.ESTADO_ADD_BUSH);
        System.out.println("estado atual:" + projeto.getEstado());
    }//GEN-LAST:event_bushClicked

    private void squareClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_squareClicked
        projeto.setEstado(projeto.ESTADO_ADD_SQUARE);
    }//GEN-LAST:event_squareClicked

    private void circleClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_circleClicked
        projeto.setEstado(projeto.ESTADO_ADD_CIRCLE);
    }//GEN-LAST:event_circleClicked

    private void tuboClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tuboClicked
        projeto.setEstado(projeto.ESTADO_ADD_TUBO);
    }//GEN-LAST:event_tuboClicked

    private void palmClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_palmClicked
        // TODO add your handling code here:
        projeto.setEstado(projeto.ESTADO_ADD_PALM);
    }//GEN-LAST:event_palmClicked

    private void flowerClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_flowerClicked
        // TODO add your handling code here:
        projeto.setEstado(projeto.ESTADO_ADD_FLOWER);
    }//GEN-LAST:event_flowerClicked

    private void rockClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rockClicked
             // TODO add your handling code here:
        projeto.setEstado(projeto.ESTADO_ADD_ROCK);
    }//GEN-LAST:event_rockClicked

    private void fountaneClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fountaneClicked
        // TODO add your handling code here:
        projeto.setEstado(projeto.ESTADO_ADD_FOUNTAIN);
    }//GEN-LAST:event_fountaneClicked

    private void poolClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_poolClicked
        // TODO add your handling code here:
        projeto.setEstado(projeto.ESTADO_ADD_POOL);
    }//GEN-LAST:event_poolClicked

    private void lakeClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lakeClicked
        // TODO add your handling code here:
        projeto.setEstado(projeto.ESTADO_ADD_LAKE);
    }//GEN-LAST:event_lakeClicked

    private void houseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_houseClicked
        // TODO add your handling code here:
         projeto.setEstado(projeto.ESTADO_ADD_HOUSE);
    }//GEN-LAST:event_houseClicked

    private void bridgeClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bridgeClicked
        // TODO add your handling code here:
         projeto.setEstado(projeto.ESTADO_ADD_BRIDGE);

    }//GEN-LAST:event_bridgeClicked

    private void wallClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_wallClicked
        // TODO add your handling code here:
              projeto.setEstado(projeto.ESTADO_ADD_WALL);
    }//GEN-LAST:event_wallClicked

    private void fenceClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fenceClicked
        // TODO add your handling code here:
             projeto.setEstado(projeto.ESTADO_ADD_FENCE);
    
    }//GEN-LAST:event_fenceClicked

    private void faucetClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_faucetClicked
        // TODO add your handling code here:
         projeto.setEstado(projeto.ESTADO_ADD_FAUCET);
        
    }//GEN-LAST:event_faucetClicked

    private void elbowClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_elbowClicked
        // TODO add your handling code here:
          projeto.setEstado(projeto.ESTADO_ADD_ELBOW);
    }//GEN-LAST:event_elbowClicked

    private void uniontClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_uniontClicked
        projeto.setEstado(projeto.ESTADO_ADD_UNIONT);
    }//GEN-LAST:event_uniontClicked

    private void tubohClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tubohClicked
        // TODO add your handling code here:
           projeto.setEstado(projeto.ESTADO_ADD_TUBO1);
    }//GEN-LAST:event_tubohClicked

    private void endClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_endClicked
        // TODO add your handling code here:
            projeto.setEstado(projeto.ESTADO_ADD_END);
    }//GEN-LAST:event_endClicked

    private void bListaMateriaisMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bListaMateriaisMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_bListaMateriaisMouseClicked

    private void checkSave(){
        int save=0;
        save = projeto.saveDados();
        if (save ==1){
            JOptionPane.showMessageDialog(rootPane, "erro");
        }
    }
    
    
    private void showJOPane(boolean newProject){
        Component frame = null;
        int n = JOptionPane.showConfirmDialog(frame,"Changes have been made to the current project. Do you wish to save?","An Inane Question",JOptionPane.YES_NO_OPTION);
        File currentFileName;

        
        // Novo Projeto
        if (newProject == true) {
            if (n == 0) {
                //YES quer gravar  
                checkSave();
                currentFileName = showJFileChooser(null, 0);
                Projeto projeto = new Projeto(currentFileName);
                this.projeto = projeto;
            } else {
                //NO descarta
                currentFileName = showJFileChooser(null, 0);
                Projeto projeto = new Projeto(currentFileName);
                this.projeto = projeto;
            }
        }
        
        // abrir Projeto
        if (newProject == false) {
            if (n == 0) {
                //YES quer gravar  
                checkSave();
                currentFileName = showJFileChooser(null, 1);
                Projeto projeto = new Projeto(currentFileName);
                this.projeto = projeto;
            } else {
                //NO descarta
                currentFileName = showJFileChooser(null, 1);
                Projeto projeto = new Projeto(currentFileName);
                this.projeto = projeto;
            }
        }
    }
    
    /*
     * fileChooserOption
     * 0 - New file
     * 1 - Open file
     * 2 - 
     */
    private File showJFileChooser(File currentFile, int fileChooserOption){
        String filename = File.separator+"tmp";
        JFileChooser fc = new JFileChooser(new File(filename));
        Component frame = null;
        File selFile = null;
        
        if (fileChooserOption==0){
           fc.showDialog(frame, "New File");
           selFile = fc.getSelectedFile();
        }
        
        if (fileChooserOption==1){
           fc.showOpenDialog(frame);
           selFile = fc.getSelectedFile();
        }
        
        return selFile;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new JanelaPrincipal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private gardenmaker.AreaDesenho areaDesenho;
    private javax.swing.JToggleButton bCircle;
    public javax.swing.ButtonGroup bGroupFlora;
    public javax.swing.ButtonGroup bGroupLimite;
    private javax.swing.ButtonGroup bGroupOrnamento;
    private javax.swing.ButtonGroup bGroupTubagem;
    private javax.swing.ButtonGroup bGroupVarios;
    private javax.swing.JMenu bListaMateriais;
    private javax.swing.JToggleButton bRectangle;
    private javax.swing.JToggleButton bTubo;
    private javax.swing.JToggleButton bush;
    private javax.swing.JPanel cardHolder;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToggleButton jToggleButton10;
    private javax.swing.JToggleButton jToggleButton11;
    private javax.swing.JToggleButton jToggleButton12;
    private javax.swing.JToggleButton jToggleButton13;
    private javax.swing.JToggleButton jToggleButton14;
    private javax.swing.JToggleButton jToggleButton15;
    private javax.swing.JToggleButton jToggleButton16;
    private javax.swing.JToggleButton jToggleButton2;
    private javax.swing.JToggleButton jToggleButton3;
    private javax.swing.JToggleButton jToggleButton4;
    private javax.swing.JToggleButton jToggleButton5;
    private javax.swing.JToggleButton jToggleButton6;
    private javax.swing.JToggleButton jToggleButton7;
    private javax.swing.JToggleButton jToggleButton8;
    private javax.swing.JToggleButton jToggleButton9;
    private gardenmaker.ToolLimite toolLimite;
    private javax.swing.JToggleButton tree;
    // End of variables declaration//GEN-END:variables
}
